# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.22.1)

# Declares and names the project.

project("jniPdfium")
message("use platform CMAKE_ANDROID_ARCH_ABI: ${ANDROID_ABI}, current CMAKE_SOURCE_DIR path: ${CMAKE_SOURCE_DIR}")
SET(CMAKE_CXX_FLAGS "-Wno-error=format-security -Wno-error=pointer-sign -DHAVE_PTHREADS")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

add_library(c++_shared STATIC IMPORTED)
add_library(modpng STATIC IMPORTED)
add_library(modft2 STATIC IMPORTED)
add_library(modpdfium STATIC IMPORTED)

set_target_properties( # Specifies the target library.
        c++_shared
        # Specifies the parameter you want to define.
        PROPERTIES IMPORTED_LOCATION

        # Provides the path to the library you want to import.
        ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libc++_shared.so)

set_target_properties(modpng PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libmodpng.so)
set_target_properties(modft2 PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libmodft2.so)
set_target_properties(modpdfium PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libmodpdfium.so)


# 查找当前目录下的所有源文件，并保存到 DIR_LIB_SRCS 变量
aux_source_directory(${CMAKE_SOURCE_DIR}/src DIR_LIB_SRCS)

add_library( # Sets the name of the library.
        jniPdfium
        # Sets the library as a shared library.
        SHARED
        # Provides a relative path to your source file(s).
        ${CMAKE_SOURCE_DIR}/src/mainJNILib.cpp)

# 导入当前目录下的所有头文件
#include_directories(.)

#find_library(c++_shared c++_shared)
#find_library(modpng, modpng)
#find_library(modft2, modft2)
#find_library(modpdfium, modpdfium)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.


find_library(log-lib log)
find_library(android android)
find_library(jnigraphics jnigraphics)

target_link_libraries( # Specifies the target library.
        jniPdfium

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib} ${android} ${jnigraphics} c++_shared modpng modft2 modpdfium)